/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pe.gov.mtc.dgac.licencias.persistence;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import pe.gov.mtc.dgac.licencias.bean.HorasTO;
import pe.gov.mtc.dgac.licencias.exception.TransactionException;
/**
 *
 * @author externo.gamaro
 */
public class HorasImplDAO extends SqlMapClientTemplate implements HorasDAO {
   Log logger = LogFactory.getLog(this.getClass());

    public HashMap insertHoras(HorasTO hora) throws TransactionException {
          HashMap result=null;
          List list=null;
      try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pCodCli",hora.getCod_cliente()); 
          parmMap.put("pCodCliOper",hora.getCod_clie_oper()); 
          parmMap.put("pAno",hora.getAnoHora()); 
          parmMap.put("pMes",hora.getMesHora()); 
          parmMap.put("pHoraIFR",hora.getHoraIfr()); 
          parmMap.put("pHoraDiurno",hora.getHoraDiurno()); 
          parmMap.put("pHoraNocturno",hora.getHoraNocturno()); 
          parmMap.put("pHoraInternac",hora.getHoraInter()); 
          parmMap.put("pUsuario",hora.getUsuarioCrea()); 
                   
          queryForObject("Horas.insertHoras", parmMap);
          list=(List)parmMap.get("pResult");
          result=(HashMap) list.get(0);
          
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return result;
    }

    public HashMap updateHoras(HorasTO hora) throws TransactionException {
          HashMap result=null;
          List list=null;
      try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pCodHora",hora.getCodHoras()); 
          parmMap.put("pCodCli",hora.getClienteoperador().getCod_cliente()); 
          parmMap.put("pAno",hora.getAnoHora()); 
          parmMap.put("pMes",hora.getMesHora()); 
          parmMap.put("pHoraIFR",hora.getHoraIfr()); 
          parmMap.put("pHoraDiurno",hora.getHoraDiurno()); 
          parmMap.put("pHoraNocturno",hora.getHoraNocturno()); 
          parmMap.put("pHoraInternac",hora.getHoraInter()); 
          parmMap.put("pUsuario",hora.getUsuarioMod()); 
                   
          queryForObject("Horas.updateHoras", parmMap);
          list=(List)parmMap.get("pResult");
          result=(HashMap) list.get(0);
          
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return result;
    }

    public HashMap deleteHoras(HorasTO hora) throws TransactionException {
        HashMap result=null;
          List list=null;
      try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pCodHora",hora.getCodHoras()); 
          parmMap.put("pCodCli",hora.getClienteoperador().getCod_cliente()); 
                            
          queryForObject("Horas.deleteHoras", parmMap);
          list=(List)parmMap.get("pResult");
          result=(HashMap) list.get(0);
          
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return result;
    }

    public List<HorasTO> selectHoras(HorasTO hora) throws TransactionException {
         List<HorasTO> list=null;
      try{
          Map<String, Object> parmMap = new HashMap<String, Object>();
			
	  parmMap.put("pCodHora",hora.getCodHoras()); 
          parmMap.put("pCodCliOper",hora.getClienteoperador().getCodClieOper()); 
          parmMap.put("pCodCli",hora.getClienteoperador().getCod_cliente()); 
                            
          queryForObject("Horas.selectHoras", parmMap);
          list=(List<HorasTO>)parmMap.get("pResult");
                    
      }catch(Exception e){
        e.printStackTrace();
	logger.error(e);
      }
       return list;
    }
   
}
